﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Newtonsoft.Json;
using System.Runtime.Serialization;
namespace ModernShopping.AppCode
{
    [DataContract]
    public class Marker
    {

        public const int NONE = 0;
        public const int INSERT = 1;
        public const int UPDATE = 2;
        public const int DELETE = 3;

        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public string Address { get; set; }
        [DataMember]
        public double Longitude { get; set; }
        [DataMember]
        public double Latitude { get; set; }
        public int Code { get; set; }
        public int Command { get; set; }

        public static List<Marker> ParseList(List<Store> lstStore)
        {
            List<Marker> listMarker = new List<Marker>();
            foreach (Store st in lstStore)
            {
                Marker mk = new Marker(st.Name, st.Address, st.Longitude, st.Latitude, NONE, st.Code);
                listMarker.Add(mk);
            }
            return listMarker;
        }

        public static string ParseListJson(List<Store> lstStore)
        {
            List<Marker> listMarker = new List<Marker>();
            foreach (Store st in lstStore)
            {
                Marker mk = new Marker(st.Name, st.Address, st.Longitude, st.Latitude, NONE, st.Code);
                listMarker.Add(mk);
            }
            return JsonConvert.SerializeObject(listMarker);
        }

        public Marker(string Name, string Address, double Longitude, double Latitude, int Command, int Code)
        {
            this.Name = Name;
            this.Address = Address;
            this.Longitude = Longitude;
            this.Latitude = Latitude;
            this.Command = Command;
            this.Code = Code;
        }

        public Store ToStore()
        {
            Store store = new Store();
            store.Name = this.Name;
            store.Address = this.Address;
            store.Longitude = this.Longitude;
            store.Latitude = this.Latitude;
            store.Code = this.Code;

            return store;
        }
    }
}